<!DOCTYPE html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <link href="/assets/focusManagement.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script>
      run(async function () {
        const directLine = testHelpers.createDirectLineWithTranscript([
          {
            attachments: [
              {
                contentType: 'application/vnd.microsoft.card.hero',
                content: {
                  tap: {
                    type: 'imBack',
                    value: 'Hello, World.'
                  },
                  subtitle:
                    'The first `imBack` is from mouse click. The second is from `ENTER` key. The third is from `SPACEBAR` key.',
                  title: 'Tap on this card to say, "echo Hello, World."'
                }
              }
            ],
            from: {
              id: 'bot',
              role: 'bot'
            },
            id: '1',
            timestamp: new Date().toISOString(),
            type: 'message'
          }
        ]);

        WebChat.renderWebChat(
          {
            directLine,
            store: testHelpers.createStore(),
            styleOptions: { subtle: '#666' }
          },
          document.getElementById('webchat')
        );

        await pageConditions.uiConnected();

        // When using runHookActivityMiddleware, an additional hidden activities will be rendered to run the hook function. Thus, minNumActivitiesShown must be +1.
        await pageConditions.numActivitiesShown(1);

        const renderer = document.querySelector('.webchat__adaptive-card-renderer');
        const card = renderer.querySelector('.ac-adaptiveCard[tabindex="0"]');

        expect(card).toBeTruthy();

        await host.click(renderer);

        await pageConditions.numActivitiesShown(2);

        card.focus();
        await host.sendKeys('\n');

        await pageConditions.numActivitiesShown(3);

        card.focus();
        await host.sendKeys(' ');

        await pageConditions.numActivitiesShown(4);

        await pageConditions.scrollToBottomCompleted();
        await host.snapshot('local');
      });
    </script>
  </body>
</html>
